package com.chocus.core.service.product;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chocus.core.bean.product.Sku;
import com.chocus.core.bean.product.SkuQuery;
import com.chocus.core.dao.product.ColorDao;
import com.chocus.core.dao.product.SkuDao;

@Service("skuService")
public class SkuServiceImpl implements SkuService {

	@Autowired
	private SkuDao skuDao;
	@Autowired
	private ColorDao colorDao;

	/**
	 * 查询sk列表
	 * 
	 * @param productId
	 * @return
	 */
	public List<Sku> getSkuList(Long productId) {
		SkuQuery skuQuery = new SkuQuery();
		skuQuery.createCriteria().andProductIdEqualTo(productId);
		List<Sku> skuList = skuDao.selectByExample(skuQuery);
		for (Sku sku : skuList) {
			sku.setColor(colorDao.selectByPrimaryKey(sku.getColorId()));
		}
		return skuList;
	}

	/**
	 * 修改sku
	 * 
	 * @return
	 */
	public int updateSku(Sku sku) {
		return skuDao.updateByPrimaryKeySelective(sku);
	}
}
